package cloudspace.stats;

import java.util.Observable;


public class StatTime extends AbstractStat
{
    Long lastUpdate = new Long( 0 );


    public void setup(
        String key,
        int bronze,
        int silver,
        int gold,
        String units )
    {
        super.setup( key, bronze, silver, gold, units );
        super.value = System.currentTimeMillis();
    }


    public void update( Observable o, Object arg )
    {
        value = System.currentTimeMillis();
    }


    public Level getLevel()
    {
        Long hours = getValue();

        if ( hours < bronze )
        {
            return Level.NONE;
        }
        else if ( hours < silver )
        {
            return Level.BRONZE;
        }
        else if ( hours < gold )
        {
            return Level.SILVER;
        }
        return Level.GOLD;
    }


    public Long getValue()
    {
        Long intermValue = ( System.currentTimeMillis() - value );
        intermValue /= 1000; // reduce to seconds
        // int seconds = (int)(intermValue % 60);
        intermValue /= 60; // reduce to minutes
        // int minutes = (int)(intermValue % 60);
        intermValue /= 60;
        return intermValue;
    }


    public AbstractStat instanceOf()
    {
        StatTime clone = new StatTime();
        return clone;

    }

}
